package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.Convolution2;
import com.miyake.dsp.osa.lab.OperatorSetting;
import com.miyake.dsp.osa.lab.LabUiAnnotation;
@LabUiAnnotation(caption="Edge Filter")
public class EdgeFilterWrapper extends Calculator {
	public static final String INPUT = "Input";
	public static final String OUTPUT = "Output";
	private OperatorSetting setting;

	public EdgeFilterWrapper(OperatorSetting setting) {
		this.setting = setting;
		initInput(INPUT);
		initOutput(OUTPUT);
	}
	
	@Override
	public void process() {
		double[] operator = new double[3];
		if (setting.getOperator().equals(OperatorSetting.Operator.Diff)) {
			operator[0] = 0;
			operator[1] = 1;
			operator[2] = -1;
		}
		else if (setting.getOperator().equals(OperatorSetting.Operator.Lablacian)) {
			operator[0] = -1;
			operator[1] = 2;
			operator[2] = -1;				
		}
		else if (setting.getOperator().equals(OperatorSetting.Operator.Sobel)) {
			operator[0] = -1;
			operator[1] = 0;
			operator[2] = 1;			
		}	
		
		setOutput(OUTPUT, new Convolution2().getResult(
				new ComplexArray(operator).getRealPart(),
				this.getInput(INPUT).getRealPart() )
				);
	}

	@Override
	public Object getSetting() {
		return this.setting;
	}

}
